package com.way.v1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 魏彪
 */
public class PromotionStrategyFactory {

    interface PromotionKey {
        String COUPON = "COUPON";
        String CASHBACK = "CASHBACK";
        String GROUP = "GROUP";
    }

    private static final Map<String, IPromotionStrategy> PROMOTION_STRATEGY_MAP = new HashMap<>();

    static {
        PROMOTION_STRATEGY_MAP.put(PromotionKey.COUPON, new CouponStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.CASHBACK, new CashbackStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.GROUP, new GroupByStrategy());
    }

    private static final IPromotionStrategy EMPTY = new EmptyStrategy();

    private PromotionStrategyFactory() {
    }

    public static IPromotionStrategy getPromotionStrategy(String key) {
        IPromotionStrategy strategy = PROMOTION_STRATEGY_MAP.get(key);
        return strategy == null ? EMPTY : strategy;
    }

}
